﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BS_2.VTKClass
{
    public class P3D
    {
        public P3D(float x, float y, float z)
        {
            this.x = x;
            this.y = y;
            this.z = z;
        }

        public float getX()
        {
            return x;
        }

        public void setX(float x)
        {
            this.x = x;
        }

        public float getY()
        {
            return y;
        }

        public void setY(float y)
        {
            this.y = y;
        }

        public float getZ()
        {
            return z;
        }

        public void setZ(float z)
        {
            this.z = z;
        }

        float x, y, z;

        override
       public bool Equals(Object obj)
        {

            if (obj == this) return true;
            if (obj is P3D)
            {
                P3D other = (P3D)obj;
                return getX() == other.getX() && getY() == other.getY() && getZ() == other.getZ();
            }
            else return false;
        }

        /**
         * 点乘
         * */
        public float dotProduct(float x, float y, float z)
        {
            return getX() * x + getY() * y + getZ() * z;
        }

        public float dotProduct(P3D vector)
        {
            return dotProduct(vector.getX(), vector.getY(), vector.getZ());
        }

        /**
       * 叉乘
       * */
        public P3D crossProduct(float x, float y, float z)
        {
            float ax = getX();
            float ay = getY();
            float az = getZ();

            return new P3D(
                    ay * z - az * y,
                    az * x - ax * z,
                    ax * y - ay * x);
        }
        public P3D crossProduct(P3D vector)
        {
            return crossProduct(vector.getX(), vector.getY(), vector.getZ());
        }

        public P3D add(float x, float y, float z)
        {

            return new P3D(this.x + x, this.y + y, this.z + z);
        }

        internal P3D add(P3D nor2)
        {
            return add(nor2.getX(), nor2.getY(), nor2.getZ());
        }
    }
}
